<script setup>
import axios from "axios";
import {ref} from "vue";
import CourseQuestionComponent from "@/components/form/right/genminghui/CourseQuestionComponent.vue";
const tableData = ref([])

const userData = ref(null);

const storedData = localStorage.getItem('key');
if (storedData) {
  userData.value = JSON.parse(storedData);
}
// const data = userData.value ? userData.value.data : null;

const consultantId=userData.value.data.consultantId;

const showInfo=function (){
  axios.get("/courseReviews/selectByConsultantId?consultantId="+consultantId)
      .then((res)=>{
        console.log(res.data.data);
        tableData.value = res.data.data;
      })
      .catch((error)=>{
        console.log(error)
      })
  }

showInfo()

// const addReview=function (){
//
// }

//删除
const del=function (index){
  axios.delete("/courseReviews/deleteById?id="+tableData.value[index].reviewId)
      .then((res)=>{
        console.log(res.data);
        showInfo()
      })
      .catch(error=>{
        console.log(error)
      })
}

</script>

<template>
  <div class="box">
<!--    <button @click="addReview" style="height:25px;font-size: 14px;background-color: rgba(64,158,255,0.81);width: 100px;text-align:  center;cursor:pointer;border-radius: 10px;color: white;border: none;float: none">添加</button>-->

    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="username" label="会员昵称" />
      <el-table-column prop="reviewContent" label="评价内容" />
      <el-table-column prop="reviewTime" label="评价时间"/>
      <el-table-column prop="starRating" label="评分" />
      <el-table-column prop="courseId" label="课程id" />

      <el-table-column label="删除" width="150">
        <template #default="scope">
          <button @click="del(scope.$index)"  style="height:25px;font-size: 14px;background-color: rgba(64,158,255,0.81);width: 100px;text-align:  center;cursor:pointer;border-radius: 10px;color: white;border: none;float: none">删除</button>
        </template>
      </el-table-column>

      </el-table>
  </div>



</template>

<style scoped>

.box{
  margin-top: 20px;
}
</style>